﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZS_PGTZControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            CustomGridView CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            if (!base.Page.IsPostBack)
            {
                Bind();
            }
            if (!_EluZSDataProvider.IsNetZSAdmin(userid) && !_EluZSDataProvider.IsZSAdmin(userid) && !_EluZSDataProvider.IsSZSB(userid))
            {
                CustomGridList1.Columns[5].Visible = false;
            }
            CustomGridList1.OnLoadData += new EventHandler(CustomGridList1_OnLoadData);
            Button btnsearch = (Button)FindControl("btnSeach");
            Button button1 = (Button)FindControl("button1");
            btnsearch.Click += new EventHandler(btnSeach_Click);
            button1.Click += new EventHandler(button1_Click);
            foreach (GridViewRow gvr in CustomGridList1.Rows)
            {
                Button btn_tj = (Button)gvr.FindControl("btn_tj");
                btn_tj.Click += new EventHandler(ChangeStatus);
            }
        }
        protected string ckComType()
        {
            string dwlb = string.Empty;
            if (!string.IsNullOrEmpty(userid))
            {
                string cid = _EluZSDataProvider.GetSomeStr("zs_user_company", "cid", "userid", userid);
                if (!string.IsNullOrEmpty(cid)) { dwlb = _EluZSDataProvider.GetSomeStr("zs_company", "单位类别", "id", cid); }
            } return dwlb;
        }
        protected void btnSeach_Click(object sender, EventArgs e)
        {
            Bind();
        }
        protected void button1_Click(object sender, EventArgs e)
        {
            string falg = base.Page.Request["flag"];
            if (!string.IsNullOrEmpty(falg))
            {
                if (falg == "pgjg")
                {
                    base.Page.Response.Redirect("ZS_PGJGBMInfo.aspx?PNID=" + base.Page.Request["PNID"]);
                }
            }
            else
            {
                base.Page.Response.Redirect("ZS_PGFBSQ.aspx?PNID=" + base.Page.Request["PNID"]);
            }
        }
        protected void Bind()
        {
            string strpnid = base.Page.Request["PNID"];
            string strsid = base.Page.Request["SID"];
            TextBox txtCName = (TextBox)FindControl("txtCName");
            CustomGridView CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            CustomGridList1.RowCreated += new GridViewRowEventHandler(CustomGridList1_RowCreated);
            DataTable dt = _EluZSDataProvider.GetPGTZXX(strpnid, strsid, txtCName.Text.Trim());
            CustomGridList1.DataSource = dt;
            CustomGridList1.RecordCount = dt.Rows.Count;
            CustomGridList1.PageSize = 10;
            CustomGridList1.DataKeyNames = new string[] { "ID", "审批状态" };
            CustomGridList1.DataBind();
        }
        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
            Bind();
        }
        protected void CustomGridList1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            CustomGridView CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            foreach (GridViewRow gvr in CustomGridList1.Rows)
            {
                if (CustomGridList1.DataKeys[gvr.RowIndex].Values["审批状态"].ToString() == "0")
                {
                    Button btn = (Button)gvr.FindControl("btn_tj");
                    btn.Enabled = true;
                }
            }
        }
        protected void ChangeStatus(object sender, EventArgs e)
        {
            CustomGridView CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            Button btn = sender as Button;
            GridViewRow gvr = btn.Parent.Parent as GridViewRow;
            string sID = CustomGridList1.DataKeys[gvr.RowIndex].Values["ID"].ToString();
            bool Change = _EluZSDataProvider.ChangeZT("ZS_PGBMJL", "审批状态", sID, "1");
            if (Change)
            {
                EluZSProvider.PGBMJL pgbmjl = _EluZSDataProvider.GetPgbmjl(sID);
                string pnid = pgbmjl.PNID;
                string comid = pgbmjl.COMID;
                string cktype = pgbmjl.审批状态;
                if (cktype == "1") {
                    string comname = _EluZSDataProvider.GetSomeStr("ZS_COMPANY", "单位名称", "ID", comid);
                    EluZSProvider.Prono prono = _EluZSDataProvider.GetProno(pnid);
                    string temp = prono.征收评估机构;
                    if (string.IsNullOrEmpty(temp))
                    {
                        _EluZSDataProvider.UpdateSomething("ZS_PRONO", "征收评估机构", comname, "ID", pnid);
                    }
                    else {
                        temp = temp + "," + comname;
                        _EluZSDataProvider.UpdateSomething("ZS_PRONO", "征收评估机构", temp, "ID", pnid);
                    }
                }
                Bind();
            }
        }
    }
}


